/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.github.lzyzsd.circleprogress.utils.properties;

import com.github.lzyzsd.circleprogress.ResourceTable;
import com.github.lzyzsd.circleprogress.utils.properties.IInterface.AttributeObserver;
import com.github.lzyzsd.circleprogress.utils.properties.IInterface.ResourcePropertyHolder;
import com.github.lzyzsd.circleprogress.utils.properties.model.ArcProgressModel;
import ohos.agp.components.AttrSet;
import ohos.agp.utils.Color;
import ohos.app.Context;
import ohos.global.resource.solidxml.TypedAttribute;

public class ArcProgressResPropertyHolder extends ResourcePropertyHolder<ArcProgressModel> {
    public ArcProgressResPropertyHolder(Context context, AttrSet attrSet) {
        super(context,attrSet);
    }

    @Override
    public ArcProgressModel obtainProperty() {
        model = new ArcProgressModel(getContext());
        AttrHelper patternElementHelper = new AttrHelper(getContext(),getAttrSet());
        patternElementHelper.getTypeAttribute("finishedStrokeColor", TypedAttribute.COLOR_ATTR, (AttributeObserver<Color>) object -> model.setFinishedStrokeColor(object));
        patternElementHelper.getTypeAttribute("unfinishedStrokeColor", TypedAttribute.COLOR_ATTR, (AttributeObserver<Color>) object -> model.setUnfinishedStrokeColor(object));
        patternElementHelper.getTypeAttribute("textColor", TypedAttribute.COLOR_ATTR, (AttributeObserver<Color>) object -> model.setTextColor(object));
        patternElementHelper.getTypeAttribute("textSize", TypedAttribute.FLOAT_ATTR, (AttributeObserver<Integer>) object -> model.setTextSize( (object)));
        patternElementHelper.getTypeAttribute("arcAngle", TypedAttribute.FLOAT_ATTR, (AttributeObserver<Integer>) object -> model.setArcAngle(object));
        patternElementHelper.getTypeAttribute("strokeWidth", TypedAttribute.FLOAT_ATTR, (AttributeObserver<Integer>) object -> model.setStrokeWidth( (object)));
        patternElementHelper.getTypeAttribute("suffixTextSize", TypedAttribute.FLOAT_ATTR, (AttributeObserver<Integer>) object -> model.setSuffixTextSize( object));
        patternElementHelper.getTypeAttribute("suffixText", TypedAttribute.STRING_ATTR, (AttributeObserver<String>) object -> model.setSuffixText(object));
        patternElementHelper.getTypeAttribute("suffixTextPadding", TypedAttribute.FLOAT_ATTR, (AttributeObserver<Integer>) object -> model.setSuffixTextPadding( (object)));
        patternElementHelper.getTypeAttribute("bottomTextSize", TypedAttribute.FLOAT_ATTR, (AttributeObserver<Integer>) object -> model.setBottomTextSize( object));
        patternElementHelper.getTypeAttribute("bottomText", TypedAttribute.STRING_ATTR, (AttributeObserver<String>) object -> model.setBottomText(object));
        patternElementHelper.getTypeAttribute("max", TypedAttribute.INTEGER_ATTR, (AttributeObserver<Integer>) object -> model.setMax(object));
        patternElementHelper.getTypeAttribute("progress", TypedAttribute.INTEGER_ATTR, (AttributeObserver<Integer>) (object) -> model.setProgress(object));
        return model;
    }
}
